package cn.hs.controller;/**
 * @author Jovan Hou 2024/10/24
 **/

import cn.hs.entity.Charge;
import cn.hs.entity.Consult;
import cn.hs.entity.Fm;
import cn.hs.service.ChargeService;
import cn.hs.util.Result;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @ClassName ChargeController
 * @Description TODO
 * @Author CnYuu
 * @Date 2024年10月24日 11:04
 * @Version 1.0
 */

@RestController
@RequestMapping("/charge")
public class ChargeController
{
    @Autowired
    private ChargeService service;

    @GetMapping("/selectAll")
    public Result selectAll(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            Charge charge,
            @RequestParam(required = false) String consult_name
    ){
        charge.setConsult(new Consult(consult_name));
        PageInfo fms = service.findAll(pageNum, pageSize, charge);
        // 用户不存在
        return Result.success(fms);
    }


    @PostMapping("/insert")
    public Result insert(
            @RequestBody
            Charge charge
    ){
        int insert = service.insert(charge);
        return Result.success(insert);
    }

    @GetMapping("/delete")
    public Result delete(
            @Param("id")
            Integer id
    ){
        int i = service.delete(id);
        return Result.success(i);
    }




@GetMapping("selectAllConsult")

public Result selectAllConsult(){

    List<Consult> consults = service.selectAllConsult();
    return Result.success(consults);
}


    @PostMapping("/update")
    public Result update(
            @RequestBody Charge charge
    ){
        int update = service.update(charge);
        return Result.success(update);
    }

    @GetMapping("/selectByConsultId")
    public Result selectByConsultId(Integer consultId){
        List<Charge> charges = service.selectByConsultId(consultId);
        if(charges.isEmpty()){
            return Result.error();
        }else {
            return Result.success(charges);
        }

    }


}
